#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const int N=200;
int score[22] = {0, 12, 9, 7, 5, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0};
int a[N];
void solve()
{
    for(int i=1;i<=20;i++)
    {
        int p, k;
        cin >> p >> k;
        a[i] += k + score[p];
    }
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    for(int i=1;i<=20;i++)
    {
        cout << i << " " << a[i] << "\n";
    }
   return 0;
}
